package com.itheima.springboottlias.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;


import java.io.IOException;
//1.自定义过滤器类，实现Filter接口
@Slf4j
//3.配置过滤器 设置过滤的路径，/*表示过滤所有路径
//@WebFilter(urlPatterns = "/*")
public class Myfilter  implements Filter {

    //2.重写核心过滤方法
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        log.info("拦截请求");
        //解析判断请求数据包中的数据，对数据进行统一的字符编码处理
        //放行操作
        filterChain.doFilter(servletRequest,servletResponse);

        //处理响应结果
        response.setStatus(404);
        log.info("拦截响应");


    }


}
